//
//  VKMeJiFenChildController.m
//  V-Learn
//
//  Created by liubo on 2019/1/9.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKMeJiFenChildController.h"
#import "VKMeJiFenChildCell.h"
#import "VKMeJiFenChildModel.h"
#import "WKJifenModel.h"
@interface VKMeJiFenChildController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSString *index;
@property (nonatomic, strong) NSArray *huoquJArray;
@property (nonatomic, strong) NSArray *xiaofeiArray;
@end

@implementation VKMeJiFenChildController
-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
-(UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen cz_screenWidth], [UIScreen cz_screenHeight] - 265-44) style:UITableViewStylePlain];
        _tableView.tableFooterView = [UIView new];//[UIScreen cz_screenHeight] - 285-25
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        _tableView.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
        _tableView.rowHeight = 60;
        _tableView.estimatedRowHeight = UITableViewAutomaticDimension;
    }
    return _tableView;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = @[];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
   NSString *index = [[NSUserDefaults standardUserDefaults] objectForKey:@"Jifenxiaofei"];

    self.index = index;
    [self tableView];
    
    [WYHXNetWorkManager get:WKMeQueryQueryIntegralRecord params:@{@"token":[UserModel getUserModel].token} completionHandler:^(id responseObj, NSError *error) {
        NSString *code = responseObj[@"code"];
        if ([code integerValue]==200) {
            NSDictionary *dict = responseObj[@"data"];
            NSArray *arr = dict[@"getIntegralRecardVOList"];
            NSArray *arr2 = dict[@"consumeIntegralRecardVOList"];
            self.huoquJArray = [VKMeJiFenChildModel mj_objectArrayWithKeyValuesArray:arr];
            self.xiaofeiArray = [VKMeJiFenChildModel mj_objectArrayWithKeyValuesArray:arr2];
        }
        [self.tableView reloadData];
    }];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 64;
    return UITableViewAutomaticDimension;
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return 10;
    if ([self.index isEqualToString:@"1"]) {
            return self.xiaofeiArray.count;
    }else{

        return self.huoquJArray.count;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    VKMeJiFenChildCell *cell = [VKMeJiFenChildCell cellWithTableView:tableView];
    if ([self.index isEqualToString:@"0"]) {
        VKMeJiFenChildModel *model = self.huoquJArray[indexPath.row];
        cell.model = model;
    }else{
        VKMeJiFenChildModel *model = self.xiaofeiArray[indexPath.row];
        cell.model = model;
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end
